import os
import shutil


def clear_file():
    # 用例执行前清除result目录的截图图片
    file_path = os.path.abspath(__file__)  # 项目根目录
    project_path = os.path.dirname(os.path.dirname(file_path))

    result_path = os.path.join(project_path, "result")  # result目录
    print(result_path)

    report_path = os.path.join(result_path, "report")  # report目录
    print(report_path)

    allure_path = os.path.join(result_path, "allure")  # allure目录
    print(allure_path)

    log_path = os.path.join(result_path, "log")  # log目录
    print(log_path)

    screenshots_path = os.path.join(result_path, "screenshots")  # screentshots目录
    print(screenshots_path)

    rmtotal=[screenshots_path,log_path,report_path,allure_path]

    files = os.listdir(result_path)

    for i in rmtotal:
        if i[i.rfind("\\")+1:] not in files:
            os.mkdir(i)
        else:
            shutil.rmtree(i)
            os.mkdir(i)

if __name__ == '__main__':
    clear_file()

